package com.mianshi.facejava.modules.facejava.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mianshi.facejava.common.utils.PageUtils;
import com.mianshi.facejava.common.utils.Query;

import com.mianshi.facejava.modules.facejava.dao.JavaQuestionDao;
import com.mianshi.facejava.modules.facejava.entity.JavaQuestionEntity;
import com.mianshi.facejava.modules.facejava.service.JavaQuestionService;


@Service("javaQuestionService")
public class JavaQuestionServiceImpl extends ServiceImpl<JavaQuestionDao, JavaQuestionEntity> implements JavaQuestionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper entityWrapper = new EntityWrapper<JavaQuestionEntity>();
        Object type = params.get("type");
        Object pointS = params.get("pointS");
        Object pointE = params.get("pointE");
        Object keyword = params.get("keyword");
        if(type != null && StringUtils.isNotBlank(type.toString())){
            entityWrapper.eq("type",type.toString());
        }
        if(pointS != null && StringUtils.isNotBlank(pointS.toString())){
            entityWrapper.ge("level",pointS);
        }
        if(type != null && StringUtils.isNotBlank(pointE.toString())){
            entityWrapper.le("level",pointE);
        }
        if(keyword != null && StringUtils.isNotBlank(keyword.toString())){
            entityWrapper.like("question", "%" + keyword + "%");
        }
        Page<JavaQuestionEntity> page = this.selectPage(
                new Query<JavaQuestionEntity>(params).getPage(),
            entityWrapper
        );

        return new PageUtils(page);
    }
}
